#include "common.h"

#define DEF_ERROR(a) {a, #a}


using namespace Scenic::Renderer;


struct ErrorName
{
	int error;
	char *name;
};

ErrorName errorNames[] = 
{
	DEF_ERROR(D3D_OK),
    DEF_ERROR(D3DOK_NOAUTOGEN),
    DEF_ERROR(D3DERR_CONFLICTINGRENDERSTATE),
    DEF_ERROR(D3DERR_CONFLICTINGTEXTUREFILTER),
    DEF_ERROR(D3DERR_CONFLICTINGTEXTUREPALETTE),
    DEF_ERROR(D3DERR_DEVICELOST),
    DEF_ERROR(D3DERR_DEVICENOTRESET),
    DEF_ERROR(D3DERR_DRIVERINTERNALERROR),
    DEF_ERROR(D3DERR_INVALIDCALL),
    DEF_ERROR(D3DERR_INVALIDDEVICE),
    DEF_ERROR(D3DERR_MOREDATA),
    DEF_ERROR(D3DERR_NOTAVAILABLE),
    DEF_ERROR(D3DERR_NOTFOUND),
    DEF_ERROR(D3DERR_OUTOFVIDEOMEMORY),
    DEF_ERROR(D3DERR_TOOMANYOPERATIONS),
    DEF_ERROR(D3DERR_UNSUPPORTEDALPHAARG),
    DEF_ERROR(D3DERR_UNSUPPORTEDALPHAOPERATION),
    DEF_ERROR(D3DERR_UNSUPPORTEDCOLORARG),
    DEF_ERROR(D3DERR_UNSUPPORTEDCOLOROPERATION),
    DEF_ERROR(D3DERR_UNSUPPORTEDFACTORVALUE),
    DEF_ERROR(D3DERR_UNSUPPORTEDTEXTUREFILTER),
    DEF_ERROR(D3DERR_WRONGTEXTUREFORMAT),
    DEF_ERROR(E_FAIL),
    DEF_ERROR(E_INVALIDARG),
    DEF_ERROR(E_OUTOFMEMORY),
    DEF_ERROR(S_OK),
	{0, 0}
};

char *Scenic::Renderer::getErrorName(int code)
{
	int i = 0;

	while(errorNames[i].name) {
		if(errorNames[i].error == code)
			return errorNames[i].name;
		i++;
	}
	return "No error name found";
}
